PostgreSQL Setup (Linux Live Server)
Install PostgreSQL
Run the following commands in the Linux terminal:
sudo apt update
sudo apt install postgresql postgresql-contrib -y
Start and Enable PostgreSQL
sudo systemctl start postgresql
sudo systemctl enable postgresql
Verify status:
sudo systemctl status postgresql
Set Root Password
Switch to the PostgreSQL system user:
sudo -i -u postgres
Open the PostgreSQL terminal:
psql
Set a password for the postgres superuser:
ALTER USER postgres WITH PASSWORD 'your_strong_password';
PostgreSQL Superuser Password
Note down this password. It is the main admin credential for PostgreSQL. Losing it will lock you out.
Exit the PostgreSQL terminal:
\q
Exit the postgres system user:
exit
Allow Password Authentication
Edit the pg_hba.conf file:
sudo nano /etc/postgresql/*/main/pg_hba.conf
Find this line:
local all postgres peer
Change it to:
local all postgres md5
Save and exit (Ctrl+O, Enter, Ctrl+X).
Restart PostgreSQL
sudo systemctl restart postgresql
Create Database and User
Log in to PostgreSQL:
psql -U postgres -h localhost
Run the following commands:
CREATE DATABASE whoxa;
CREATE USER whoxa_user WITH PASSWORD 'your_strong_password';
GRANT ALL PRIVILEGES ON DATABASE whoxa TO whoxa_user;
\q
Verify the database was created:
psql -U postgres -h localhost -c "\l"
Configure Environment Variables
In your backend .env file, set:
DB_HOST=localhost
DB_PORT=5432
DB_NAME=whoxa
DB_USER=whoxa_user
DB_PASSWORD=your_strong_password
Run Migrations
cd whoxa-whatsapp-business-api
npx sequelize-cli db:migrate
npx sequelize-cli db:seed:all
tip
If connection fails, verify PostgreSQL is running (sudo systemctl status postgresql) and the credentials in .env match what you set above.